package controller

import (
	"hft/Database/admin"
	"hft/Http/Models/request"
	services "hft/Http/Services"
	utils "hft/Http/Utils"

	"github.com/gin-gonic/gin"
)

type Property struct{}

func (*Property) CreateProperty(c *gin.Context) {
	var property *admin.Property

	c.ShouldBindJSON(&property)

	err := services.PropertyService.CreateProperty(property)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*Property) EditProperty(c *gin.Context) {

	var property *admin.Property

	c.ShouldBindJSON(&property)

	err := services.PropertyService.EditProperty(property)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*Property) GetPropertyList(c *gin.Context) {

	list, err := services.PropertyService.GetPropertyList()

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(list, c)

}

func (*Property) Delete(c *gin.Context) {

	var IDS *request.IDS

	c.ShouldBindJSON(&IDS)

	err := services.PropertyService.Delete(IDS.IDS)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

var PropertyController = new(Property)
